/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.dog.service.impl;

import com.dog.dao.VacancyDAO;
import com.dog.model.ContactPerson;
import com.dog.model.Vacancy;
import com.dog.service.IContactPersonService;
import com.dog.service.IVacancyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * User: Kuttubek Aidaraliev
 * Date: 02.04.2010
 * Time: 08:52:04
 */
//@Transactional(rollbackFor = {NullPointerException.class})

@Service
public class VacancyService extends BaseService<VacancyDAO, Vacancy> implements IVacancyService {

    @Autowired
    private VacancyDAO vacancyDAO;

    @Autowired
    private IContactPersonService contactPersonService;

    @Override
    public VacancyDAO getDao() {
        return vacancyDAO;
    }

    @Override
    public Vacancy getByIdWithContactPersons(Long vacancyId) {
        return getDao().getByIdWithContactPersons(vacancyId);
    }

    @Override
    public void addContactPerson(Long vacancyId, Long contactPersonId) {
        Vacancy vacancy = getByIdWithContactPersons(vacancyId);
        ContactPerson contactPerson = contactPersonService.get(contactPersonId);
        vacancy.getContactPersons().add(contactPerson);
        vacancyDAO.update(vacancy);
    }

    @Override
    public void deleteContactPerson(Long vacancyId, Long contactPersonId) {
        Vacancy vacancy = getByIdWithContactPersons(vacancyId);
        ContactPerson contactPerson = contactPersonService.get(contactPersonId);
        vacancy.getContactPersons().remove(contactPerson);
        vacancyDAO.update(vacancy);
    }

}
